<?php
/**
 * Created by PhpStorm.
 * User: meiyun1
 * Date: 2017/2/23
 * Time: 下午2:03
 */

namespace App\Models\ActivityModelTemplate;

class ActivityModelTemplateRepository implements \App\Contracts\Repositories\ActivityModelTemplateRepository
{
    public function create(ActivityModelTemplate $activityModelTemplate)
    {
        // TODO: Implement create() method.
        if (!is_null($activityModelTemplate->id)) {
            throw new \Exception('duplicate id');
        }
        if ($activityModelTemplate->save()) {
            return $activityModelTemplate;
        }
        return false;
    }

    public function findByModel($model_id="")
    {
        // TODO: Implement findByModel() method.
        $queryBuild = ActivityModelTemplate::query();
        $conditions = array();
        if (!empty($model_id)) {
            $conditions[] = ['model_id','=',$model_id];
        }
        $res = $queryBuild->where($conditions)->get();
        $str ="{\"screen_type\":\"full\",\"limit\":1,\"page_configs\":{\"button\":{\"enable\":false}},\"prizes\":[],\"share_configs\":{\"step\":1},\"type\":\"wap\"}";
        return $res;
    }

    /**
     * @param $id
     * @return ActivityModelTemplate
     */
    public function findOne($id)
    {
        return ActivityModelTemplate::query()->find($id);
    }
}
